package com.byt.base;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;

import com.byt.base.utils.LogUtil;

import java.util.List;

/**
 * base 应用的Application
 */

public class BaseApplication extends Application {
    // 这个是不会出现oom的这个是随着整个应用
    public static Application mApplication;
    public static boolean mIsDebug;

    public static void setDebug(boolean isDebug) {
        mIsDebug = isDebug;
        LogUtil.init(mApplication, isDebug);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mApplication = this;
    }


    /**
     * 获取进程名
     *
     * @param context
     * @return
     */
    public static String getCurrentProcessName(Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
        if (runningApps == null) {
            return null;
        }
        for (ActivityManager.RunningAppProcessInfo proInfo : runningApps) {
            if (proInfo.pid == android.os.Process.myPid()) {
                if (proInfo.processName != null) {
                    return proInfo.processName;
                }
            }
        }
        return null;
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }
}
